//
//  MainNewsViewController.m
//  LoveCar
//
//  Created by Xue Senhong on 15/5/21.
//  Copyright (c) 2015年 薛森鸿. All rights reserved.
//

#import "VideoCell.h"
#import "UIImageView+WebCache.h"

@implementation VideoCell

- (void)dealloc
{
    [_myImageView release];
    [_title release];
    [_time release];
    [_replyCount release];
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        // 图片
        self.myImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.myImageView];
        [_myImageView release];
        
        // 标题
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:self.title];
        [self.title setFont:[UIFont systemFontOfSize:16]];
        // 标题label自适应文本高度
        [self.title setNumberOfLines:0];
        [self.title sizeToFit];
        [_title release];
        
        // 日期
        self.time = [[UILabel alloc] init];
        [self.contentView addSubview:self.time];
        [self.time setTextColor:[UIColor grayColor]];
        self.time.font = [UIFont systemFontOfSize:12];
        [_time release];
        
        // 评论数
        self.replyCount = [[UILabel alloc] init];
        [self.contentView addSubview:self.replyCount];
        [self.replyCount setTextColor:[UIColor grayColor]];
        self.replyCount.font = [UIFont systemFontOfSize:12];
        [self.replyCount setTextAlignment:NSTextAlignmentRight];
        [_replyCount release];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 图片
    [self.myImageView setFrame:CGRectMake(10, 10, self.contentView.bounds.size.width / 3 + 10, self.contentView.bounds.size.height - 20)];
    
    // 标题
    [self.title setFrame:CGRectMake(self.contentView.bounds.size.width / 3 + 30, 10, self.contentView.bounds.size.width - (self.contentView.bounds.size.width / 3 + 20) - 20, (self.contentView.bounds.size.height - 20) / 2)];
    
    // 日期
    [self.time setFrame:CGRectMake(self.contentView.bounds.size.width / 3 + 30, (self.contentView.bounds.size.height - 10) / 3 * 2, self.contentView.bounds.size.width - (self.contentView.bounds.size.width / 3 + 20) - 100, (self.contentView.bounds.size.height - 20) / 3)];
    
    // 评论数
    [self.replyCount setFrame:CGRectMake(self.contentView.bounds.size.width / 3 + self.contentView.bounds.size.width - (self.contentView.bounds.size.width / 3 + 10) - 70, (self.contentView.bounds.size.height - 10) / 3 * 2, 70, (self.contentView.bounds.size.height - 20) / 3)];
    
}

- (void)valueforCellWithArticle:(Article *)article
{
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:article.smallimg] placeholderImage:[UIImage imageNamed:@"preloadPic.png"]];
    [self.title setText:article.title];
    [self.time setText:article.time];
    [self.replyCount setText:[NSString stringWithFormat:@"%@播放", article.playcount]];   
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
